package com.tiancheng.onecode.controller.admin;

/**
 * @Author: kellen
 * @Description: B端用户登录控制器
 * @Date: create in 2024/12/10 10:52
 */

import com.tiancheng.onecode.model.auth.UserSubjectProfile;
import com.tiancheng.onecode.model.request.admin.UserPwdLoginReq;
import com.tiancheng.onecode.model.request.admin.UserRegisterReq;
import com.tiancheng.onecode.model.response.Result;
import com.tiancheng.onecode.service.IUserService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: kellen
 * @Description: 商户管理 admin controller
 * @Date: create in 2024/12/9 21:27
 */
@RestController
@RequestMapping("/admin")
public class LoginController {

    @Resource
    private IUserService userService;

    /**
     * 用户注册
     * @param userRegisterReq
     * @return
     */
    @PostMapping("/register")
    public Result register(@RequestBody @Valid UserRegisterReq userRegisterReq){
        userService.register(userRegisterReq);
        return Result.success("注册用户成功，请登录！");
    }

    /**
     * 用户注册
     * @param userPwdLoginReq 账号密码登录请求
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody @Valid UserPwdLoginReq userPwdLoginReq){
        final UserSubjectProfile userSubjectProfile = userService.pwdLogin(userPwdLoginReq);
        return Result.success(userSubjectProfile);
    }

}
